package com.yuxi.al.leercode;

/**
 * 数字反转
 * Created by yuxi on 2017/3/30.
 */
public class ReverseInteger {
    public static void main(String[] args) {
        int num = -128;
        System.out.println(1111);
        int res = reverseInteger(num);
        System.out.println(res);

    }

    /**
     * 数字反转  做法/10 %10
     *
     * @param x 反转数字
     * @return
     */
    private static int reverseInteger(int x) {
        int result = 0;
        while (x != 0) {
            //尾数
            int tail = x % 10;
            //因为要做除法。所以在做除法之前先做乘法
            result = result * 10 + tail;
            x = x / 10;
        }
        return result;
    }
}
